package com.ruoyi.system.service.impl;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.ShopCompanyInfo;
import com.ruoyi.system.mapper.ShopCompanyInfoMapper;
import com.ruoyi.system.mapper.ShopUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ShopSoftwareMapper;
import com.ruoyi.system.domain.ShopSoftware;
import com.ruoyi.system.service.IShopSoftwareService;

/**
 * 软件池列Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-03
 */
@Service
public class ShopSoftwareServiceImpl implements IShopSoftwareService 
{
    @Autowired
    private ShopSoftwareMapper shopSoftwareMapper;
    @Autowired
    private ShopCompanyInfoMapper shopCompanyInfoMapper;
    @Autowired
    private ShopUserMapper shopUserMapper;
    /**
     * 查询软件池列
     * 
     * @param softwareId 软件池列主键
     * @return 软件池列
     */
    @Override
    public ShopSoftware selectShopSoftwareBySoftwareId(Long softwareId)
    {
        return shopSoftwareMapper.selectShopSoftwareBySoftwareId(softwareId);
    }
    /**
     * 查询软件池列
     *
     * @param softwareId 软件池列主键
     * @return 软件池列
     */
    @Override
    public ShopSoftware selectShopSoftwareBySoftwareAndCompanyId(Long softwareId)
    {
        return shopSoftwareMapper.selectShopSoftwareBySoftwareAndCompanyId(softwareId);
    }

    /**
     * 查询软件池列列表
     * 
     * @param shopSoftware 软件池列
     * @return 软件池列
     */
    @Override
    public List<ShopSoftware> selectShopSoftwareList(ShopSoftware shopSoftware)
    {
        List<ShopSoftware> shopSoftwareList = shopSoftwareMapper.selectShopSoftwareList(shopSoftware);
        if (shopSoftwareList != null) {
            for (ShopSoftware soft : shopSoftwareList) {
                ShopCompanyInfo companyInfo = shopCompanyInfoMapper.selectShopCompanyInfoByCompanyId(soft.getCompanyId());
                soft.setCompanyName(companyInfo.getCompanyName());
            }
        }
        return shopSoftwareList;
    }


    @Override
    public List<Map> querySoftwareList(ShopSoftware parms)
    {
         //拼接查询条件
         String[] serviceProcess = parms.getServiceProcessArry();
         String[] industry = parms.getIndustryArry();
         String serviceProcessSql = "";
         String industrySql = "";

        if(serviceProcess!=null && serviceProcess.length>0){
            serviceProcessSql = String.join("|", serviceProcess);
            serviceProcessSql = ",("+serviceProcessSql+"),";
        }

        if(industry!=null && industry.length>0){
            industrySql = String.join("|", industry);
            industrySql = ",("+industrySql+"),";
        }

        parms.setServiceProcess(serviceProcessSql);
        parms.setIndustry(industrySql);
        return shopSoftwareMapper.querySoftwareList(parms);
    }


    /**
     * 新增软件池列
     * 
     * @param shopSoftware 软件池列
     * @return 结果
     */
    @Override
    public int insertShopSoftware(ShopSoftware shopSoftware)
    {
        shopSoftware.setCreateTime(DateUtils.getNowDate());
        return shopSoftwareMapper.insertShopSoftware(shopSoftware);
    }

    /**
     * 修改软件池列
     * 
     * @param shopSoftware 软件池列
     * @return 结果
     */
    @Override
    public int updateShopSoftware(ShopSoftware shopSoftware)
    {
        shopSoftware.setUpdateTime(DateUtils.getNowDate());
        return shopSoftwareMapper.updateShopSoftware(shopSoftware);
    }

    /**
     * 批量删除软件池列
     * 
     * @param softwareIds 需要删除的软件池列主键
     * @return 结果
     */
    @Override
    public int deleteShopSoftwareBySoftwareIds(Long[] softwareIds)
    {
        return shopSoftwareMapper.deleteShopSoftwareBySoftwareIds(softwareIds);
    }

    /**
     * 删除软件池列信息
     * 
     * @param softwareId 软件池列主键
     * @return 结果
     */
    @Override
    public int deleteShopSoftwareBySoftwareId(Long softwareId)
    {
        return shopSoftwareMapper.deleteShopSoftwareBySoftwareId(softwareId);
    }

    @Override
    public ShopSoftware getShopSoftwareTotal()
    {
        return shopSoftwareMapper.getShopSoftwareTotal();
    }

    @Override
    public List<ShopSoftware> selectShopSoftwareList1(ShopSoftware shopSoftware) {

        return shopSoftwareMapper.selectShopSoftwareList1(shopSoftware);
    }


}
